﻿package bdz.pv3d.extensions.utils
{
	import flash.geom.Matrix;
	import org.papervision3d.core.geom.Vertex3D;
	import flash.display.Sprite;
	import flash.display.LineScaleMode;
	import flash.display.CapsStyle;
	
	public class Line3DSegment
	{
		
		 
		public var color:int;
		public var size:int;
		public var vertex1:Vertex3D;
		public var vertex2:Vertex3D;
		public var scaledSize:Number;
		
		public function Line3DSegment(v1:Vertex3D, v2:Vertex3D, lineProps:Object = null)
		{
			this.color = lineProps ? lineProps.color : 0xFFFFFF;
			this.size = this.scaledSize = lineProps ? lineProps.thickness : 1;
			vertex1 = v1;
			vertex2 = v2;
		}
		
			
		public function render(container:Sprite, scaled:Boolean = false, alpha:Number = 1):int
		{

			if(vertex1.vertex2DInstance.visible &&  vertex2.vertex2DInstance.visible){
				var s:Number = scaled ? this.scaledSize : this.size;
				container.graphics.lineStyle(s, color, alpha, false, LineScaleMode.NONE, CapsStyle.ROUND);
				container.graphics.moveTo(vertex1.vertex2DInstance.x, vertex1.vertex2DInstance.y);
				container.graphics.lineGradientStyle("linear", [color, color *2], [1,.5], [255, 255] );
				container.graphics.lineTo(vertex2.vertex2DInstance.x, vertex2.vertex2DInstance.y);
				
			}
			return 1;	
		}
	
	}
}